<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js" type="text/javascript"></script>
</head>
<body>
    <div id="app">
        <h2>总价格：{{totalPrice}}</h2>
    </div>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                books: [
                    {id: 1001, name: "bookName", price: 79},
                    {id: 1002, name: "bookName", price: 101},
                    {id: 1003, name: "bookName", price: 67},
                    {id: 1004, name: "bookName", price: 89},
                ]
            },
            // computed: 计算属性
            computed: {
                totalPrice: function(){
                    let totalPrice = 0;
                    for(let i in this.books){ // i等于下标
                        totalPrice = totalPrice + this.books[i].price;
                    }
                    return totalPrice;
                }
            }
        })
    </script>
</body>
</html>